#ifndef GAMEWIDGET_H
#define GAMEWIDGET_H

#include <QGraphicsScene>// 2D场景  类
#include <QGraphicsView>// 2D视图   显示用
#include "playerplane.h"
#include "map.h"
#include "bullet.h"
#include "enemyplane.h"
#include "bomb.h"
#include <QSqlDatabase>
#include <QSqlQuery>

namespace Ui {
class GameWidget;
}

class GameWidget : public QWidget
{
    Q_OBJECT

public:
    explicit GameWidget(int map_path,int plane_path,QWidget *parent = nullptr);
    ~GameWidget();

    void insert_data(QString user_name);

    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
    void create_map();
    void create_player_plane();
    void createEnemies();
    void checkCollisions1();
    void checkCollisions2();
    void create_bomb(double b_x,double b_y);
    int flag = 0; // 死亡检测
    PlayerPlane *player_plane; // player
    Map *back_ground; // 背景
    QProgressBar *blood_bar; // 血条
    QLabel *score_label; // 得分label
    int score; // 得分

    int map_path;
    int plane_path;

    QSqlDatabase db; // 数据库
    QSqlQuery *query;
public slots:
        void background_move_timer_slot();
signals:
        void game_close();
private:
    Ui::GameWidget *ui;
    QGraphicsScene *scene;
    QGraphicsView *view;

    QTimer *enemy_timer;//敌机出现定时器
    QTimer *collision_timer1;
    QTimer *collision_timer2;
    QTimer *background_move_timer;
};

#endif // GAMEWIDGET_H
